using System;
using System.Data;
using System.Collections;
using System.Text;

using EntLibEC.Cmn;
using System.Transactions;

using EntLibEC.Dac;
using EntLibEC.Dac.Online;

using EntLibEC.Info.Online;

namespace EntLibEC.Biz.Online
{
	/// <summary>
	/// Summary description for FeedBackManager.
	/// </summary>
	public class FeedBackManager
	{
		private FeedBackManager()
		{
		}
		private static FeedBackManager _instance;
		public static FeedBackManager GetInstance()
		{
			if( _instance == null )
			{
				_instance = new FeedBackManager();
			}
			return _instance;
		}
		public void Insert(FeedBackInfo oParam)
		{
			new FeedBackDac().Insert(oParam);
		}
		public void Update(Hashtable ht)
		{
			new FeedBackDac().Update(ht);
		}
		private void map(FeedBackInfo oParam, DataRow tempdr)
		{
			oParam.SysNo = Util.TrimIntNull(tempdr["SysNo"]);
			oParam.Subject = Util.TrimNull(tempdr["Subject"]);
			oParam.Suggest = Util.TrimNull(tempdr["Suggest"]);
			oParam.NickName = Util.TrimNull(tempdr["NickName"]);
			oParam.Email = Util.TrimNull(tempdr["Email"]);
			oParam.Phone = Util.TrimNull(tempdr["Phone"]);
			oParam.Memo = Util.TrimNull(tempdr["Memo"]);
			oParam.Note = Util.TrimNull(tempdr["Note"]);
			oParam.CreateTime = Util.TrimDateNull(tempdr["CreateTime"]);
			oParam.UpdateTime = Util.TrimDateNull(tempdr["UpdateTime"]);
			oParam.Status = Util.TrimIntNull(tempdr["Status"]);
		}
		public FeedBackInfo Load(int sysno)
		{
			string sql = "select * from Ent_Feedback where sysno = " + sysno;
			DataSet ds = SqlHelper.ExecuteDataSet(sql);
			if ( !Util.HasMoreRow(ds))
				return null;
			FeedBackInfo oInfo = new FeedBackInfo();
			map(oInfo, ds.Tables[0].Rows[0]);
			return oInfo;
		}
		public DataSet GetFeedBackDs(Hashtable paramHash)
		{
			string sql = @" select * from Ent_Feedback where 1=1";
			if ( paramHash != null && paramHash.Count != 0 )
			{
				StringBuilder sb = new StringBuilder(100);
				foreach(string key in paramHash.Keys)
				{
					sb.Append(" and ");
					object item = paramHash[key];
					if ( key == "DateFrom")
					{
						sb.Append("CreateTime >= ").Append(Util.ToSqlString(item.ToString()));
					}
					else if ( key == "DateTo")
					{
						sb.Append("CreateTime <= ").Append(Util.ToSqlEndDate(item.ToString()));
					}
					else if ( item is int)
					{
						sb.Append(key).Append("=" ).Append(item.ToString());
					}
					else if (key == "SysNo")
					{
						sb.Append("SysNo = ").Append(int.Parse(item.ToString()));
					}
					else if ( item is string)
					{
						sb.Append(key).Append(" like ").Append(Util.ToSqlLikeString(item.ToString()));
					}
				}
				sql += sb.ToString();
			}
			else
			{
				sql = sql.Replace("select", "select top 50");
			}

			sql += " order by sysno desc";
			return SqlHelper.ExecuteDataSet(sql);
		}
	}
}
